package com.app.couponsharelife.ui.view

import android.view.View
import androidx.viewpager.widget.ViewPager

/**
 *Created by xct on 2019/1/9
 *Description:
 */
class ScaleTransformer: ViewPager.PageTransformer{
    private val MIN_SCALE = 0.9f
    override fun transformPage(page: View, position: Float) {
        var pos= when {
            position < -1 -> (-1).toFloat()
            position > 1 -> 1.toFloat()
            else -> position
        }
        /**
         * 判断是前一页 1 + position ，右滑 pos -> -1 变 0
         * 判断是后一页 1 - position ，左滑 pos -> 1 变 0
         */
        val tempScale = if (pos < 0) 1 + pos else 1 - pos // [0,1]
        val scaleValue = MIN_SCALE + tempScale*0.1f // [0,1]
        page.scaleX = scaleValue
        page.scaleY = scaleValue
    }
}